<%@include file="/WEB-INF/pages/commons/commons.jsp"%>

<c:set var="title" value="Blog - ${actionBean.blog.name}" scope="request" />
<c:set var="name" value="${actionBean.blog.name}" scope="request"/>
<c:set var="description" value="${actionBean.blog.description}" scope="request" />

<stripes:layout-render name="${_blogThemePath}/blog_layout.jsp" _title="${title}" _blogName="${name}" _blogDescription="${description}">

    <stripes:layout-component name="head">
        <script type="text/javascript">
            $(document).ready(function() {
                $("#preview").click(function(){
                    $("#display").html("loading ...");
                    var param = new Array();
                    param.push({name:'previewComment',value:''});
                    param.push({name:'entry',value:'${actionBean.entry.id}'});
                    param.push({name:'comment',value:$("#comment").val()});
                    $.post(
                        '<stripes:url beanclass="foo.bar.blog.web.action.general.BlogActionBean"/>',
                        param,
                        function(data) {
                            $("#display").hide();
                            $("#display").html(data);
                            $("#display").fadeIn();
                        }
                    );
                    return false;
                });

                $("#commandHelp").click(function() {
                    window.open('<stripes:url beanclass="foo.bar.blog.web.action.general.RenderEngineCommandHelpActionBean" />',
                            'commandHelp', 'status=1,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,height=500,width=500');
                    return false;
                });
            });
        </script>
    </stripes:layout-component>


    <stripes:layout-component name="content">
        <h1>${actionBean.entry.name}</h1>
        <p><span class="radeox"><c:out value="${actionBean.entry.decoratedContent}" escapeXml="false"/></span></p>
        <p class="date">
            <img src="<c:url value='${_blogThemePath}/images/comment.gif'/>"/>
                <stripes:link class="comments" beanclass="foo.bar.blog.web.action.general.BlogActionBean" event="viewEntry">
                    <stripes:param name="entry" value="${actionBean.entry.id}"/>
                    <stripes:param name="blog" value="${actionBean.entry.blog.id}"/>
                    Comments (<c:out value="${actionBean.entry.totalComments}"/>)
                </stripes:link>
            <img src="<c:url value='${_blogThemePath}/images/timeicon.gif'/>"/>
                Created on <fmt:formatDate value="${actionBean.entry.creationDate}" pattern="dd-MM-yyyy hh:mm:ss" />
                Published on <fmt:formatDate value="${actionBean.entry.publishDate}" pattern="dd-MM-yyyy hh:mm:ss"/>
                by <c:out value="${actionBean.entry.creator.username}"/>
            <img src="<c:url value='${_blogThemePath}/images/timeicon.gif'/>"/>
                <stripes:link class="more" beanclass="foo.bar.blog.web.action.general.BlogActionBean" event="viewEntry">
                    <stripes:param name="entry" value="${actionBean.entry.id}"/>
                    <stripes:param name="blog" value="${actionBean.entry.blog.id}"/>
                    Read full article
                </stripes:link>
        </p>
        <hr/>
            <div id="display">
            </div>
            <div>
                <c:forEach items="${actionBean.entry.comments}" var="comment" varStatus="status">
                    <p>
                     <div class="radeox">
                        <c:out value="${comment.decoratedContent}" escapeXml="false"/>
                     </div>
                    </p>
                    <p class="byline">Posted on <fmt:formatDate value="${comment.creationDate}" pattern="dd-MM-yyyy hh:mm:ss"/> by
                        <c:choose>
                            <c:when test="${not empty comment.creator}">
                                <c:out value="${comment.creator.username}"/>
                            </c:when>
                            <c:otherwise>
                                Anonymous
                            </c:otherwise>
                        </c:choose>
                    </p>
                </c:forEach>
            </div>
        <hr/>
                    <stripes:messages />
                    <stripes:errors globalErrorsOnly="true"/>

                    <c:if test="${actionBean.entry.canComment}">
                    <jsecurity:hasPermission name="blog:addBlogEntryComment:${actionBean.blog.id}">
                    <stripes:form beanclass="foo.bar.blog.web.action.general.BlogActionBean" method="POST">
                        <stripes:errors />
                        <input type="hidden" name="entry" value="${actionBean.entry.id}"/>
                        <input type="hidden" name="blog" value="${actionBean.blog.id}"/>
                        <input type="hidden" name="entryComment" value=""/>
                        <input type="hidden" name="entryComment.entry" value="${actionBean.entry.id}"/>
                        <img src="<c:url value='/kaptcha.jpg'/>"/><br/>
                        <stripes:text name="captcha" /><br/>
                        <label>Comment</label><br/>
                        <stripes:textarea id="comment" name="entryComment.content" rows="10" cols="60"/>
                        <br/><br/>
                        <stripes:submit name="saveEntryComment">Save</stripes:submit>
                        <stripes:button id="preview" name="previewComment">Preview</stripes:button>
                        <stripes:button id="commandHelp" name="commandHelp">Command Help</stripes:button>
                    </stripes:form>
                    </jsecurity:hasPermission>
                    <jsecurity:lacksPermission name="blog:addBlogEntryComment:${actionBean.blog.id}">
                        No "blogEntryComment:addBlogEntryComment:${actionBean.blog.id}" permission
                    </jsecurity:lacksPermission>
                    </c:if>
        <br/>
    </stripes:layout-component>


</stripes:layout-render>


